
    package org.example.R;

import lombok.Data;

    /**
     * 接口类型返回定义
     */
    @Data
    public class R {
        public static final int CODE_SUCCESS = 200;//请求成功
        public static final int CODE_FAILED = 400;//接口请求失败
        public static final int CODE_NOT_LOGIN = 401;//用户未登录
        public static final int CODE_ACCESS = 402;//用户无权限

        //是否成功
        private boolean success;
        //状态码
        private int code;
        //描述
        private String msg;
        //数据
        private Object data;


        /**
         * 初始化一个新创建的 AjaxResult 对象，使其表示一个空消息。
         */
        public R() {
        }

        //提供静态方法，快速创建返回对象
        public static R success(String msg) {
            R r = new R();
            r.success = true;
            r.code = CODE_SUCCESS;
            r.msg = msg;
            return r;
        }

        public static R success(String msg, Object data) {
            R success = success(msg);
            success.data = data;
            return success;
        }

        public static R error(String msg) {
            R r = new R();
            r.success = true;
            r.code = CODE_FAILED;
            r.msg = msg;
            return r;
        }

        public static R error(String msg, Object data) {
            R failed = error(msg);
            failed.data = data;
            return failed;
        }


        public R setData(Object data) {
            this.data = data;
            return this;
        }

    }